package com.thread.thread.ThreadPool线程池;

import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

public class SingleThreadPoolTest {

	//a按照顺序执行，每次都是同一个线程，多个线程会在LinkedBlockingQueue中存储，保证顺序执行
	static ExecutorService executorService= Executors.newSingleThreadExecutor();
	public static void main(String[] args) {
		ThreadLocal<String> stringThreadLocal=new ThreadLocal<>();

		Thread thread1=new Thread(()->{
			stringThreadLocal.set("菜菜");

			System.out.println("thread1"+Thread.currentThread().getName());
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});


		Thread thread2=new Thread(()->{

			System.out.println("thread2"+Thread.currentThread().getName()+"---"+stringThreadLocal.get());

		});

		executorService.submit(thread1);
		executorService.submit(thread2);

	}

}
